//此程序作用：访问特定注册表路径下的左右值value
//你可以简单粗暴地认为：键(key)=文件夹,值(value)=文件
//目标注册表路径：HKLM\HARDWARE\DESCRIPTION\System\BIOS

#include <iostream>
#include<conio.h>
#include<windows.h>
int main()
{
	long openResult;
	HKEY hKey;

	//打开文件夹
	openResult = RegOpenKeyEx(
		HKEY_LOCAL_MACHINE,         // handle to open key
		L"HARDWARE\\DESCRIPTION\\System\\BIOS",  // subkey name,是一个文件夹，里面有很多文件
		//字符串之前加上L，变为宽字符
		0,   // reserved
		KEY_QUERY_VALUE, // security access mask
		&hKey    // handle to open key
	);

	if (openResult == ERROR_SUCCESS)
	{

		DWORD dwIndex = 0;
		TCHAR valuename[MAX_PATH] = { 0 };
		DWORD len = MAX_PATH;
		BYTE keyData[MAX_PATH] = { 0 };
		DWORD dataLen = MAX_PATH;
		DWORD keyType = REG_SZ;

		long traverseResult = RegEnumValue(hKey,
			dwIndex, valuename,
			&len, 0, &keyType,
			keyData, &dataLen);

		//遍历目录下的所有项目
		while (traverseResult == ERROR_SUCCESS)
		{
			//valuename记录了该项名称,keydata记录了具体数据
			if (valuename != NULL && keyType == REG_SZ) {
				printf("key name:%ws \n data: %ws \n --------------\n", valuename, (LPCTSTR)keyData);
			}
			dwIndex++;
			len = MAX_PATH;
			dataLen = MAX_PATH;

			traverseResult = RegEnumValue(hKey,
				dwIndex, valuename,
				&len, 0, &keyType,
				keyData, &dataLen);
		}
	}

	//没找到这个目录
	else
	{
		printf("\n CPU INFO:");
		printf("UNKNOWN\n");
	}


	RegCloseKey(hKey);
	return 0;
}
